package com.mtz.controller;

        import com.mtz.VO.ResultVO;
        import com.mtz.dateobject.Answer;
        import com.mtz.service.AnswerService;
        import com.mtz.utils.ResultVOUtil;
        import io.swagger.annotations.Api;
        import io.swagger.annotations.ApiOperation;
        import io.swagger.annotations.ApiParam;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.web.bind.annotation.*;

        import java.util.List;

/**
 * @author 煜赜
 * @date 2018/12/3 0003 上午 10:23
 */
@Api(description = "答案接口")
@RestController
@RequestMapping("/ans")
public class AnswerController {

    @Autowired
    private AnswerService answerService;

    /**
     * 通过答案id查找答案
     * @param id 答案id
     * @return
     */
    @ApiOperation(value = "通过答案id查找答案", notes = "通过答案id查找答案")
    @GetMapping("/id")
    public ResultVO findById(@ApiParam(value = "答案id",required = true)
                             @RequestParam("id") Integer id) {
        Answer answer = answerService.findAnsById(id);
        return ResultVOUtil.success(answer);
    }

    /**
     * 根据问题id查找答案
     * @param questionId 问题id
     * @return
     */
    @ApiOperation(value = "根据问题id查找答案", notes = "根据问题id查找答案")
    @GetMapping("/questionId")
    public ResultVO findByQuestionId(@ApiParam(value = "问题id",required = true)
                                     @RequestParam("questionId") Integer questionId) {
        List<Answer> answerList = answerService.findAnsByQuestionId(questionId);
        return ResultVOUtil.success(answerList);
    }

    /**
     * 根据修改人查找答案
     * @param author 修改人
     * @return
     */
    @ApiOperation(value = "根据修改人查找答案", notes = "根据修改人查找答案")
    @GetMapping("/author")
    public ResultVO findByAuthor(@ApiParam(value = "修改人",required = true)
                                 @RequestParam("author") String author) {
        List<Answer> answerList = answerService.findAnsByAuthor(author);
        return ResultVOUtil.success(answerList);
    }

    /**
     * 根据答案视角查找答案
     * @param angle 答案视角
     * @return
     */
    @ApiOperation(value = "根据答案视角查找答案", notes = "根据答案视角查找答案")
    @GetMapping("/angle")
    public ResultVO findByAngle(@ApiParam(value = "答案视角(0--官方视角,1~*待设计)",required = true)
                                @RequestParam("angle") Integer angle) {
        List<Answer> answerList = answerService.findAnsByAngle(angle);
        return ResultVOUtil.success(answerList);
    }

    /**
     * 查询相应idDeleted状态的答案集
     * @param idDeleted 信息是否删除（0表示未删除，1表示删除）
     * @return 返回相应信息状态的答案集合
     */
    @ApiOperation(value = "查询相应idDeleted状态的答案集", notes = "查询相应idDeleted状态的答案集")
    @GetMapping("/idDeleted")
    public ResultVO findByIsDeleted(@ApiParam(value = "0--未删除,1--已删除,2~*--待设计",required = true)
                                    @RequestParam("idDeleted") Integer idDeleted) {
        List<Answer> answerList = answerService.findAnsByIsDeleted(idDeleted);
        return ResultVOUtil.success(answerList);
    }

    /**
     * 设置答案状态 -> 已发布
     * @param id 答案id
     * @return null
     */
    @ApiOperation(value = "设置答案状态 -> 已发布", notes = "设置答案状态 -> 已发布")
    @PostMapping("/public")
    public ResultVO publicById(@ApiParam(value = "答案id",required = true)
                               @RequestParam("id") Integer id) {
        answerService.publicAnsById(id);
        return ResultVOUtil.success();
    }

    /**
     * 删除答案
     * @param id 答案id
     * @return null
     */
    @ApiOperation(value = "删除答案", notes = "删除答案")
    @PostMapping("/delete")
    public ResultVO deleteById(@ApiParam(value = "答案id",required = true)
                               @RequestParam("id") Integer id) {
        answerService.deleteAnsById(id);
        return ResultVOUtil.success();
    }

    /**
     * 删除数据库中答案
     * @param id 答案id
     * @return null
     */
    @ApiOperation(value = "删除数据库中答案", notes = "删除数据库中答案")
    @PostMapping("/deleteTrue")
    public ResultVO deleteTrue(@ApiParam(value = "答案id",required = true)
                               @RequestParam("id") Integer id) {
        answerService.trueDelete(id);
        return ResultVOUtil.success();
    }

    /**
     * 根据问题id更新对应的答案HitCount
     * @param questionId 问题id
     * @return
     */
    @ApiOperation(value = "根据问题id更新对应的答案HitCount", notes = "根据问题id更新对应的答案HitCount")
    @PostMapping("/hitCount/questionId")
    public ResultVO updateHitCountByQuestionId(@ApiParam(value = "问题id",required = true)
                                               @RequestParam("questionId") Integer questionId) {
        answerService.updateHitCountByQuesId(questionId);
        return ResultVOUtil.success();
    }

    /**
     * 根据答案id更新对应的答案HitCount
     * @param id 答案id
     * @return
     */
    @ApiOperation(value = "根据答案id更新对应的答案HitCount", notes = "根据问题id更新对应的答案HitCount")
    @PostMapping("/hitCount/id")
    public ResultVO updateHitCountByAnsId(@ApiParam(value = "答案id",required = true)
                                          @RequestParam("id") Integer id) {
        answerService.updateHitCountByAnsId(id);
        return ResultVOUtil.success();
    }
}
